<!-- 选择文件路径 -->
<template>
  <div class="select-save-file-path">
    <el-row>
      <el-col :span="18">
        <el-input v-model="filePath" placeholder="请选择文件保存路径" readonly />
      </el-col>
      <el-col :span="6">
        <el-button @click="selectFilePath" type="primary" color="#626aef">选择路径</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
const filePath = defineModel({ default: '' })
const emits = defineEmits(['selectFilePath'])
const selectFilePath = async () => {
  try {
    const result = await window.electronAPI.showSaveDialog()
    if (!result.canceled && result.filePaths) {
      emits('selectFilePath', 'info', result.filePaths[0])
    }
  } catch (err) {
    emits('selectFilePath', 'error', err)
  }
}
</script>

<style lang="scss" scoped>
.select-save-file-path {
  width: 100%;
}
</style>
